package top.so.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import top.so.dao.ColumnArticleDao;
import top.so.entity.ColumnArticle;
import top.so.service.ColumnArticleService;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.UUID;

@Service
public class ColumnArticleServiceImpl implements ColumnArticleService {

    @Autowired
    private ColumnArticleDao columnArticleDao;

    public List<ColumnArticle> selectWithPage(ColumnArticle columnArticle, int pageNum) {
        return columnArticleDao.selectWithPage(columnArticle,pageNum);
    }

    public boolean insertColumnArticle(ColumnArticle columnArticle) {
        UUID uuid = UUID.randomUUID();
        columnArticle.setArticleID(String.valueOf(uuid).replaceAll("-",""));
        Date date = new Date();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        columnArticle.setGenTime(formatter.format(date));
        return columnArticleDao.insertColumnArticle(columnArticle);
    }

    public boolean deleteColumnArticle(ColumnArticle columnArticle) {
        return columnArticleDao.deleteColumnArticle(columnArticle);
    }

    public boolean updateColumnArticle(ColumnArticle columnArticle) {
        return columnArticleDao.updateColumnArticle(columnArticle);
    }
}
